package com.hockeo.client.metadata;

import java.util.Date;

/**
 * Describes the property of a class that has been tagged with {@link IMetadataTag}. Each
 * property corresponds to a getter method which has been found in the tagged class.
 *
 * @version $Id$
 * @author jjanke
 */
public class PropertyDescriptor
{
  /**
   * Describes the display type (i.e. the type that is used to display the property on the
   * user interface).
   */
  public enum DisplayType
  {
    BOOLEAN, DATE, NUMBER, STRING;
  }

  private final String      d_strName;
  private final Class<?>    d_clsType;
  private final DisplayType d_displayType;

  /**
   * Creates a new PropertyDescriptor.
   *
   * @param strName the name of the property
   * @param clsType the property's type
   */
  protected PropertyDescriptor( String strName, Class<?> clsType )
  {
    d_strName = strName;
    d_clsType = clsType;

    if ( d_clsType == Boolean.class )
      d_displayType = DisplayType.BOOLEAN;
    else if ( d_clsType == Date.class )
      d_displayType = DisplayType.DATE;
    else if ( d_clsType.getSuperclass() == Number.class )
      d_displayType = DisplayType.NUMBER;
    else
      d_displayType = DisplayType.STRING;
  }

  /**
   * Returns the name of the property.
   */
  public String getName()
  {
    return d_strName;
  }

  /**
   * Returns the type of the property.
   */
  public Class<?> getType()
  {
    return d_clsType;
  }

  /**
   * Returns the type that should be used for displaying this property on the user
   * interface.
   */
  public DisplayType getDisplayType()
  {
    return d_displayType;
  }
}
